
import { RecoilRoot } from 'recoil';
import Page from './page/Page';
import './index.less'
import { useEffect, useState } from 'react';
import PrintPage from './page/PrintPage';
import axios from 'axios';
// 获取url参数

axios.defaults.baseURL = 'http://localhost:8012';
const getQueryVariable = () => {
    const query = window.location.search.substring(1);
    const vars = query.split("&");
    let obj = {}
    vars.forEach(item => {
        const [key, value] = item.split('=')
        obj[key] = value
    })
    return obj
}
const data = getQueryVariable()

function App() {

    const [config, setConfig] = useState(null);
    useEffect(() => {
        axios.get('/config').then(res => {
            setConfig(res.data.data)
        })
    }, [])
    return (
        <RecoilRoot>
            <div className="App">
                {
                    data.url ? <PrintPage data={data} /> : config ? <Page config={config} /> : null
                }
            </div>
        </RecoilRoot>
    );
}

export default App;
